import dayjs from 'dayjs'

let instance
export default {
  type: 'crud',
  autoRequest: false,
  border: true,
  api: {
    url: `/predictBill/info`,
    method: 'POST',
    responseData: '',
    data: {
      billType: '04',
      bussType: 'API_COST'
    }
  },
  onMounted(e) {
    instance = e.instance
  },
  querys: [
    {
      type: 'select',
      prop: 'suppliers',
      multiple: true,
      collapseTags: true,
      checkAll: true,
      label: '合作方',
      placeholder: '请选择合作方',
      api: {
        url: '/supplier/info/selectDifSupplierInfo?status=0&bussType=API_COST',
        responseAdaptor: (response) => {
          response.data = response.data.map((item) => ({
            label: item,
            value: item
          }))
          return response
        }
      },
      event: {
        loaded: (data) => {
          if (data && data.length) {
            instance.setupState.excuteQueryFn('updateDefaultValue', {
              suppliers: [data[0].value]
            })
            instance.setupState.queryEvent()
          }
        }
      }
    },
    {
      type: 'datePicker',
      prop: 'attribMonth',
      label: '归属月',
      placeholder: '请选择归属月',
      defaultValue: dayjs().format('YYYYMM'),
      'value-format': 'YYYYMM',
      reflectAttr: {
        type: 'month'
      }
    }
  ],
  columns: [
    {
      type: 'expand',
      width: '50px',
      slots: {
        content: {
          type: 'vxe-table',
          data: '${monthPredictList}',
          body: [
            {
              type: 'vxe-column',
              title: '月份',
              field: 'month'
            },
            {
              type: 'vxe-column',
              title: '金额',
              field: 'fee'
            }
          ]
        }
      }
    },
    {
      title: '合作方',
      field: 'supplier'
    },
    {
      title: '放款月',
      field: 'attribMonth'
    },
    {
      title: '放款金额（元）',
      field: 'transAmount'
    },
    {
      title: '项目名称',
      field: 'projectInfo'
    },
    {
      title: '总预测成本（元）',
      field: 'promotionFee'
    }
  ]
}
